package com.example.deepschool.Controller.TempDownload;

import com.example.deepschool.Model.Response.ApiResponse;
import com.example.deepschool.Model.Response.ResponseData;
import com.example.deepschool.service.composite.CompositeService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.core.io.support.ResourceRegion;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Tag(name = "临时下载API")
@RestController("TempDownload")
@RequestMapping("/TempDownload")
public class Controller {
	
	@GetMapping("")
	public ResponseEntity<ResourceRegion> Temp (String TempUUID, HttpServletRequest request) {
		String Range = request.getHeader(HttpHeaders.RANGE);
		String host = request.getHeader("host");
		ResponseData responseData = CompositeService.tempDownload.Download(TempUUID, host, Range);
		return ApiResponse.GetApiResponse().binBody(responseData).downloadBuild();
	}
}
